package main

import "fmt"

func printArr1(arr [4]int){
    for index,value := range arr {
        fmt.Println("index = ",index,",value = ",value)
    }

    arr[1] = 100
}

func printArr2(arr []int){
    for index,value := range arr {
        fmt.Println("index = ",index,",value = ",value)
    }

    arr[1] = 100
}

func main(){
    // 固定长度数组
    var arr1 [10]int
    arr2 := [4]int{1,2,3,4}

    //for i := 0; i < 10; i++{
    for i := 0; i < len(arr1); i++ {
        fmt.Println(arr1[i])
    }

    for index, value := range arr2 {
        fmt.Println("index = ",index,",value = ",value)
    }

    // 查看数据类型 注意：Printf，不是 Println
    fmt.Printf("type of arr1 = %T\n",arr1)
    fmt.Printf("type of arr2 = %T\n",arr2)

    // 不能传长度不一致的数组
    // 报错：cannot use arr1 (type [10]int) as type [4]int in argument to printArr
    //printArr(arr1)

    // 传递的是值
    printArr1(arr2)
    fmt.Println("arr2[1] = ",arr2[1])

    // 不给任何长度，表示动态数组
    arr3 := []int{11,22,33,44}

    // 指针传递
    printArr2(arr3)
    fmt.Println("arr3[1] = ",arr3[1])
}